const app = getApp()
const { getUserInfo,getActivityCollect,getActivityRegistration } = require("../../utils/http/api")
const { imageUrl } = require("../../utils/http/http").dev
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //获取全局变量 导航栏的高度statusBarHeight
    top: Number(app.globalData.menu.top),
    height: Number(app.globalData.menu.height),
    userInfo:{
      avatar:"https://img1.baidu.com/it/u=2343979483,3247810365&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400",
      nickName:"伟岸",
      desc:"守护绿色环保活动，连接智慧与传统",
    },
    status:[
      {
        name:"发布话题",
        flag: false,
      },{
        name:"收藏论坛",
        flag: true
      },{
        name:"连续签到",
        flag: false
      }
    ],
    moreFeatures:[
      {
        icon: imageUrl + "/collection_color.png",
        title:"订阅中心",
        func:"toSubscribe"
      },{
        icon: imageUrl + "/download.png",
        title:"资料中心",
        func:"toDownload"
      },{
        icon:"../../images/message.png",
        title:"订单中心",
        func:"toOrder"
      },
    ]
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
    this.getCollectList()
    this.getActivityRegistration()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getUserInfo()
  },
  getActivityRegistration(){
    getActivityRegistration(3).then(res => {
      console.log("报名活动",res)
      this.setData({
        applyList: res.total
      })
    })
  },
  getCollectList(){
    let _this = this;
    getActivityCollect().then((res) => { 
      console.log("订阅活动展商列表",res)
      if (res && res.rows) {
        const collectList = res.rows;
        _this.setData({  
          collects: collectList.length
        });
      }
    }).catch((error) => {  
      console.error('请求订阅活动列表失败:', error);  
    });  
  },
  getUserInfo(){
    getUserInfo(3).then(res => {
      console.log("userInfo",res.data)
      wx.setStorageSync('userInfo',res.data)
      this.setData({
        userInfo: res.data
      })
    })
  },
  goEdit(){
    wx.navigateTo({
      url: '../ModifyData/ModifyData',
    })
  },

  //奖励互动
  goInteraction(){
    wx.navigateTo({
      url: '/pages/myself/interaction/interaction',
    })
  },

  //我的订阅
  toSubscribe(){
    wx.navigateTo({
      url: '/pages/myself/subscribe/subscribe',
    })
  },

  //下载中心
  toDownload(){
    wx.navigateTo({
      url: '/pages/myself/data/data',
    })
  },

  //订单中心
  toOrder(){
    wx.navigateTo({
      url: '/pages/myself/order/order',
    })
  },
  
  //积分中心
  toPoints(){
    wx.navigateTo({
      url: '/pages/myself/points/points',
    })
  },

  //报名中心
  toApply(){
    wx.navigateTo({
      url: '/pages/myself/apply/apply',
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})